<?php
/**
 * 套餐分组管理
 * User: 王文凡<787802868@qq.com>
 * Date: 2016/7/22 0022
 * Time: 10:35
 */
namespace Common\Model;

use Think\Model;

class AuthGroupModel extends Model
{
    protected $_validate = [
        ['title', 'require', '岗位名称必须填写！'],
        ['title', '', '岗位名已经存在！', 0, 'unique', 1],
        ['area_id', 'require', '管辖区域必须填写！'],
        ['remark', 'require', '岗位说明必须填写！']

    ];

    //新增或修改角色
    public function changeGroup($id = '')
    {
        if (!$this->create()) {
            $arr['state'] = 'error';
            $arr['info'] = $this->getError();
            return $arr;
        } else {
            //新增
            if (empty($id)) {
                if ($this->add($_POST)) {
                    $arr['state'] = 'success';
                    $arr['info'] = '新增成功';
                } else {
                    $arr['state'] = 'error';
                    $arr['info'] = '新增失败';
                }
                return $arr;
            } else {
                if ($this->where("id=%d", $id)->save($_POST)) {
                    $arr['state'] = 'success';
                    $arr['info'] = '修改成功';
                } else {
                    $arr['state'] = 'error';
                    $arr['info'] = '修改失败';
                }
                return $arr;
            }
        }
    }

    //角色信息查询
    public function lister($id)
    {
        if (empty($id)) {
            $counts = $this->where("status=%d", 1)->count();
            $page = page($counts, 20, 5);
            $list = $this->where("status=%d", 1)->limit($page->firstRow, $page->listRows)->select();
            $arr['list'] = $list;
            $arr['page'] = $page;
            return $arr;
        } else {
            return $this->where("id=%d", $id)->find();
        }
    }
}













